import axios from "axios";
import { Message } from 'element-ui';
let HttpRequest = {
    getRequest({ url, data = {}, method = "GET", header }) {
        return new Promise((resolve, reject) => {
            this._getRequest(url, header, resolve, reject, data, method);
        });
    },
    _getRequest: function (url, header, resolve, reject, data = {}, method = "GET") {
        let format = method.toLocaleLowerCase() === 'get' ? 'params' : 'data';
        let h = header === undefined ? { "content-type": "application/x-www-form-urlencoded" } : header;
        axios({
            url: url,
            method: method,
            params: data,
            header: { "content-type": "application/x-www-form-urlencoded" }
        }).then(res => {
            resolve(res.data);
        }).catch((error) => {
            reject();
            Message({
                message: "网络异常!" + error,
                type: "error",
                center: true
            });
        })
    }
};
// let RequestUrl = "http://127.0.0.1:8081/QAPortal/WIE/IVRMenuTree"; 

let RequestUrls = '';//"http://38.63.169.72:7080/QAPortal/WIE/IVRMenuTree";
// let RequestUrl = "http://38.19.64.170:7080/QAPortal/WIE/IVRMenuTree";
let TreeApi = {
    RequestUrl: RequestUrls,
    getAllTree() {
        return HttpRequest.getRequest({
            method: "GET",
            url: this.RequestUrl + "/GetAll"
        });
    },
    updateTreeNode(treeNode) {
        return HttpRequest.getRequest({ 
            method: "POST",
            url: this.RequestUrl + "/updateNode",
            data: treeNode
        });
    }
};
export { TreeApi };